export default app => {
  const { STRING, INTEGER, DATE, DataTypes, TEXT } = app.Sequelize;

  const product = app.model.define('product', {
    id: { type: INTEGER, primaryKey: true, autoIncrement: true },
    uuid: { type: STRING(36), unique: true },
    name: STRING(50),
    model: STRING(50), // 产品型号
    productNo: STRING, // 产品编号（可唯一确定产品信息）
    registrationStatus: STRING(50), // 注册情况（可选：已注册/未注册）
    address: STRING(255), // 产品地址（用户输入）
    unit: STRING(255),
    patent: STRING(255), // 所用成果
    fk_applicationArea: {
      type: DataTypes.STRING(36),
    }, // 应用领域（外键：application_area）'，外键
    description: TEXT,
    updateTime: DATE,
    filler: {
      type: DataTypes.STRING(36),
    }, // 填写人
    contactTel: STRING(50), // 联系人电话
    contactPerson: STRING(10), // 联系人姓名
    contactEmail: STRING(50), // 联系人email
    createdAt: DATE,
    updatedAt: DATE,
  });
  product.associate = () => {
    app.model.Product.belongsToMany(app.model.Patent, {
      through: app.model.MergeProductPatent,
      foreignKey: 'product_id',
      otherKey: 'patent_id',
    });
    app.model.Product.belongsToMany(app.model.Organization, {
      through: app.model.MergeProductOrganization,
      foreignKey: 'product_id',
      otherKey: 'organization_id',
    });
    app.model.Product.belongsTo(app.model.ApplicationArea, {
      foreignKey: 'fk_applicationArea',
      targetKey: 'uuid',
    });
    app.model.Product.hasMany(app.model.Image, {
      foreignKey: 'fk_product',
      sourceKey: 'uuid',
    });
  };
  return product;
};
